package com.volunteer_sys.service.Impl;

import com.volunteer_sys.Dao.ActivityDao;
import com.volunteer_sys.Utils.RedisUtils;
import com.volunteer_sys.pojo.Activity;
import com.volunteer_sys.service.AttService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AttServiceImpl implements AttService {

    @Autowired
    private ActivityDao activityDao;

    @Autowired
    private RedisUtils redisUtils;

    @Override
    public Integer getRestNumById(Integer att_id){
        return redisUtils.getRestNum(att_id);
    }

    @Override
    public Activity getAtt(Integer att_id){
        return activityDao.getAttById(att_id);
    }

    @Override
    public List<Activity> getAllAtt(){
        return activityDao.getAllAtt();
    }

    @Override
    public boolean addAtt(Activity att){
        return activityDao.addAtt(att) == 1;
    }

    @Override
    public boolean delAtt(Integer att_id){
        if(activityDao.removeAtt(att_id)==1){
            return redisUtils.removeAttCache(att_id);
        }else return false;
    }

    @Override
    public boolean openSignature(Integer att_id){
        Activity att = activityDao.getAttById(att_id);
        return redisUtils.addAttCache(att_id,att.getVolunteerNum());
    }

    @Override
    public boolean cancelSignature(Integer id){
        return redisUtils.removeAttCache(id);
    }



}
